package com.im.netty.handler.server;

import com.im.netty.message.LogoutRequestPacket;
import com.im.netty.message.LogoutResponsePacket;
import com.im.netty.session.SessionUtil;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 
 * @author yutao
 */
public class LogoutRequestHandler extends SimpleChannelInboundHandler<LogoutRequestPacket> {

	public static final LogoutRequestHandler INSTANCE = new LogoutRequestHandler();
	
	private LogoutRequestHandler() {};
	
	/**
	 * 
	 * @see io.netty.channel.SimpleChannelInboundHandler#channelRead0(io.netty.channel.ChannelHandlerContext, java.lang.Object)
	 */
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, LogoutRequestPacket msg) throws Exception {
		SessionUtil.unBindSession(ctx.channel());
		LogoutResponsePacket logoutResponsePacket = new LogoutResponsePacket();
		logoutResponsePacket.setSuccess(true);
		ctx.channel().writeAndFlush(logoutResponsePacket);
	}

}
